package com.wd.mylive.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.wd.current.model.Bean.DataBean
import com.wd.current.model.Utils.HttpUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File


/**
 * 作者: 张智聪
 * 时间: 2024/10/22
Time:  9:13
 * 描述:
 */
class LiveViewModel:ViewModel() {


    //    liveCoverImage	file	直播封面照	文件流	是
    //开直播
    var openLiveData= MutableLiveData<DataBean.OpenLiveBean>()
    fun postOpenLive(userId:Int,sessionId:String,liveTitle:String, file: File){
        val body = RequestBody.create("multipart/form-data".toMediaTypeOrNull(), file)
        val part: MultipartBody.Part = MultipartBody.Part.createFormData("liveCoverImage", file.name, body)
        HttpUtils.httpUtils.aplis2
           .postOpenLive(userId,sessionId,
            101,liveTitle,"116.4074","39.3042",part)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe {
                openLiveData.value=it
            }
    }



    //===============================主播开启搭鹊桥
     var magpieBridgeData=MutableLiveData<DataBean.PutBean>()
    fun magpieBridge(userId:Int,sessionId:String,liveId:Int){
        HttpUtils.httpUtils.aplis2.magpieBridge(userId, sessionId, liveId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe {
                magpieBridgeData.value = it
            }

    }

    var closeLiveData=MutableLiveData<DataBean.CloseLiveBean>()
    fun closeLive(userId:Int,sessionId:String){
       HttpUtils.httpUtils.aplis2
           .closeLive(userId, sessionId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe {
                closeLiveData.value=it
            }
    }
}